package com.xg.controller;


import com.xg.common.result.ApiResult;
import com.xg.common.util.PageUtil;
import com.xg.entity.UsedCar;
import com.xg.entity.UsedCarType;
import com.xg.service.IUsedCarTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

/**
 * <p>
 *  车型Controller
 * </p>
 *
 * @author jdh
 * @since 2023-03-30
 */
@Controller
@RequestMapping("/usedCarType")
public class UsedCarTypeController {

    @Autowired
    private IUsedCarTypeService iUsedCarTypeService;
    /**
     * @Author 罗迎庆
     * @Methodname queryUsedCarTypeList       
     * @Description //TODO (车辆类型查询)
     * @Date 17:05 2023/3/31
     * @Param []
     * @return com.xg.common.result.ApiResult<com.xg.entity.UsedCarType>
     **/
    @RequestMapping("queryUsedCarTypeList")
    @ResponseBody
    public ApiResult< List<UsedCarType>> queryUsedCarTypeList() {
        List<UsedCarType> list = iUsedCarTypeService.queryUsedCarTypeList();
        return ApiResult.success(list);
    }
    
    /**
     * @Author 罗迎庆
     * @Methodname        
     * @Description //TODO (根据汽车车型id查询used_car表)
     * @Date 10:33 2023/4/6
     * @Param 
     * @return 
     **/
    @RequestMapping("queryUsedCarTypeById")
    public String queryUsedCarTypeById(Model model,Integer typeId) {
        List<UsedCar> list = iUsedCarTypeService.queryUsedCarTypeById(typeId);
        model.addAttribute("usedCarTypeList",list);
        return "PurchaseCar";
    }
    

    /**
     * 列表
     * @param params
     * @return
     */
    @RequestMapping("/list")
    @ResponseBody
    public PageUtil<UsedCarType> queryPage(@RequestParam Map<String,Object> params){
        return iUsedCarTypeService.queryPage(params);
    }

    /**
     * 删除
     * @param ids
     * @return
     */
    @RequestMapping("/delete")
    @ResponseBody
    ApiResult deleteType(@RequestParam("ids") List<Integer> ids){
        return iUsedCarTypeService.deleteType(ids);
    }

    /**
     * 查询单个对象车型
     * @param typeId
     * @return
     */
    @RequestMapping("/info")
    @ResponseBody
    ApiResult<UsedCarType> selectTypeInfo(@RequestParam("typeId") Integer typeId){
        return iUsedCarTypeService.selectTypeInfo(typeId);
    }

    /**
     * 保存车型
     * @param usedCarType
     * @return
     */
    @RequestMapping("/save")
    @ResponseBody
    ApiResult saveType(@RequestBody UsedCarType usedCarType){
        return iUsedCarTypeService.saveType(usedCarType);
    }

}
